package topcoder;

public class RobotHerbDiv2 {

	public int getdist(int T, int[] a) {
		int x = 0, y = 0, d = 0;
		
		for (int t = 0; t < T; t++) {
			for (int i = 0; i < a.length; i++) {
				if ( d == 0 )
					x += a[i];
				if ( d == 1 )
					y += a[i];
				if ( d == 2)
					x -= a[i];
				if ( d == 3)
					y -= a[i];
				
				d = (d + a[i]) % 4;
			}
		}
		
		return Math.abs(x) + Math.abs(y);
	}
}
